using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Data.SqlClient;
using System.Text;
using Microsoft.Practices.CompositeUI;
using Microsoft.Practices.ObjectBuilder;
using NetROS.Tiers.Data.SqlClient;
using NetRosApp.Infrastructure.Interface.Services;
using DevExpress.XtraEditors;
using NetROS.Tiers.Data;

namespace NetRosApp.Infrastructure.Library.Services
{
   internal class SQLPasswordChanger:ISQLPasswordChanger
    {   WorkItem _workitem;

        [InjectionConstructor]
        public SQLPasswordChanger(Microsoft.Practices.CompositeUI.WorkItem work)
        {
            _workitem = work;
        }

        private SQLPromjenaPasswordaUI _forma;
       private SQLLockScreenUI _forma2;
        private SqlConnectionStringBuilder _builder;
        public void PromjeniPass()
        {
            _forma = new SQLPromjenaPasswordaUI(this);
            _builder = new SqlConnectionStringBuilder(_workitem.RootWorkItem.Items.Get("GlavniConnString") as string);
            _forma.PostaviKorisnika(_builder.UserID);
            _forma.ShowDialog();
        }

       public void Zakljucaj()
       {
           _forma2 = new SQLLockScreenUI(this);
           _builder = new SqlConnectionStringBuilder(_workitem.RootWorkItem.Items.Get("GlavniConnString") as string);
           _forma2.PostaviKorisnika(_builder.UserID);
           _forma2.ShowDialog();
       }
        public bool NoviPass(string old, string novi)
        {
            if (_builder.Password == old)
            {
                try
                {
                    SqlConnection.ChangePassword(_builder.ConnectionString, novi);
                    return true;
                }
                catch(Exception ex)
                {
                    XtraMessageBox.Show(ex.Message);
                    return false;
                }
            }
            return false;
        }
       public bool TestPass(string pass)
       {
           return _builder.Password == pass;
       }

    }
}
